/*
 * @创建文件时间: 2021-06-03 00:50:28
 * @Auther: 猿小天
 * @最后修改人: 猿小天
 * @最后修改时间: 2021-11-29 10:46:51
 * 联系Qq:1638245306
 * @文件介绍: 菜单的按钮和接口配置
 */

import { request } from '@/api/service'

export const crudOptions = (vm) => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false,
      treeConfig: { // 树形数据配置
        children: 'children',
        hasChild: 'hasChildren',
        expandAll: true
      }
    },
    rowHandle: {
      width: 220,
      view: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      }
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 24, // 默认的表单 span
      width: '300'
    },
    columns: [{
      title: '关键词',
      key: 'search',
      show: true,
      disabled: true,
      search: {
        disabled: false
      },
      form: {
        disabled: true
      },
      view: { // 查看对话框组件的单独配置
        disabled: true
      }
    },
    {
      title: '域名',
      key: 'domain',
      show: true,
      width: 'auto',
      search: {
        disabled: false
      },
      form: {
        disabled: false,
        rules: [ // 表单校验规则
          { required: true, message: '域名必填项' }
        ]
      }
    },
    {
      title: '业务类型',
      key: 'business_type',
      show: true,
      width: 90,
      type: 'radio',
      dict: {
        data: [
          { value: 'web', label: '网站加速' },
          { value: 'download', label: '文件下载加速' },
          { value: 'video', label: '点播加速' },
          { value: 'wholeSite', label: '全站加速' }
        ]
      },
      search: {
        disabled: false
      },
      form: {
        disabled: false,
        component: {
          value: 'web' // 默认值
        }
      }
    },
    {
      title: '服务范围',
      key: 'service_area',
      show: false,
      width: 120,
      type: 'radio',
      dict: {
        data: [
          { value: 'mainland_china', label: '中国大陆' },
          { value: 'outside_mainland_china', label: '大陆外区域' },
          { value: 'global', label: '全球' }
        ]
      },

      search: {
        disabled: true
      },
      form: {
        component: {
          value: 'mainland_china' // 默认值
        },
        disabled: false
      }
    },
    {
      title: '源站类型',
      key: 'origin_type',
      show: false,
      width: 90,
      type: 'radio',
      dict: {
        data: [
          { value: 'ipaddr', label: '源站IP' },
          { value: 'domain', label: '源站域名' },
          { value: 'obs_bucket', label: 'OBS桶名' }
        ]
      },
      search: {
        disabled: false
      },
      form: {
        component: {
          value: 'ipaddr' // 默认值
        },
        disabled: false
      }
    },
    {
      title: '源站地址',
      key: 'ip_or_domain',
      show: true,
      width: 'auto',
      search: {
        disabled: true
      },
      form: {
        rules: [ // 表单校验规则
          { required: true, message: '请填写回源地址' }
        ],
        disabled: false
      }
    },
    {
      title: '状态',
      key: 'status',
      show: true,
      width: 90,
      type: 'select',
      dict: {
        data: [
          { value: 'offline', label: '离线' },
          { value: 'online', label: '在线' }
        ]
      },
      search: {
        disabled: false
      },
      form: {
        disabled: true
      }
    },
    {
      title: 'https_status',
      key: 'https_status',
      show: false,
      width: 90,
      type: 'radio',
      dict: {
        data: [
          { value: '0', label: '不启用' },
          { value: '1', label: '协议跟随' },
          { value: '2', label: 'http回源' },
          { value: '3', label: 'https回源' }
        ]
      },
      search: {
        disabled: true
      },
      form: {
        component: {
          value: '1' // 默认值
        },
        disabled: false
      }
    },
    {
      title: '证书名',
      key: 'cert_name',
      type: 'select',
      width: 70,
      show: false,
      // dict: {
      //   data: vm.dictionary('cert_name')
      // },
      dict: {
        url: '/api/config/basic/?limit=999',
        value: 'value', // 数据字典中value字段的属性名
        label: 'value', // 数据字典中label字段的属性名
        getData: (url) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            const obj = ret.data.data.find(o => o.name === 'cert_name')
            return [obj]
          })
        }
      },
      form: {
        component: {
          span: 12
        },
        rules: [ // 表单校验规则
          { required: true, message: '请选择证书' }
        ]
      },
      component: { props: { color: 'auto' } } // 自动染色
    },
    {
      title: 'CNAME',
      key: 'cname',
      show: true,
      width: 'auto',
      search: {
        disabled: false
      },
      form: {
        disabled: true
      }
    },
    {
      title: '域名解析',
      key: 'domain_resolve',
      show: false,
      width: 'auto',
      type: 'switch',
      search: {
        disabled: false
      },
      form: {
        component: {
          value: false // 默认值
        },
        disabled: false
      }
    },
    {
      title: '描述',
      key: 'description',
      show: true,
      width: 'auto',
      form: {
        component: {
          value: '请输入描述信息' // 默认值
        },
        disabled: false
      }
    }
    ]
  }
}
